package com.qn.mapper;

import com.qn.dto.UserDTO;
import com.qn.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.Map;

@Mapper(componentModel = "spring")
public interface UserConverter {


    /**
     * UserDTO属性拷贝至User
     * UserDTO属性数量多于User
     * 属性名称与类型相同
     *
     * @param userDTO
     */
    User userDTOtoUser(UserDTO userDTO);

    @Mappings({
            @Mapping(expression = "java(map.get(\"id\"))", target = "id"),
            @Mapping(expression = "java(map.get(\"name\"))", target = "name"),
            @Mapping(expression = "java(map.get(\"passWord\"))", target = "passWord"),
            @Mapping(expression = "java(map.get(\"phoneNumber\"))", target = "phoneNumber")
    })
    User mapper(Map<String, String> map);
}

